
import HospitalAPI from '../api/hospital.js';

export const Hospital={
   state:{
      hospitallist:[],
      hospital_total_count:0,
      editHospitalStatus:-1,     //插入状态 0失败  1成功  -1不改变
      hospitalinfo:[],
      delHospitalStatus:-1,       //删除状态
      allhospitallevel:[
         {label:'三级甲等',value:'1'},
         {label:'三级乙等',value:'2'},
         {label:'三级丙等',value:'3'},
         {label:'二级甲等',value:'4'},
         {label:'二级乙等',value:'5'},
         {label:'二级丙等',value:'6'},
         {label:'一级甲等',value:'7'},
         {label:'一级乙等',value:'8'},
         {label:'一级丙等',value:'9'},
         {label:'其他',value:'10'}
      ]
   },
   mutations:{
      setHospitalList(state,list){
          state.hospitallist=list;
      },
      setHospitalTotalCount(state,total_count){
          state.hospital_total_count=total_count;
      },
      setEditHospitalStatus(state,status){
          state.editHospitalStatus=status;
      },
      setHospitalInfo(state,info){
          state.hospitalinfo=info;
      },
      setDelHospitalStatus(state,status){
          state.delHospitalStatus=status;
      }
   },
   actions:{
      loadHospitalList(context,data){
          HospitalAPI.getHospitalList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setHospitalList',response.data.list);
                  context.commit('setHospitalTotalCount',response.data.total_count);
              }
          })
      },
      //插入Hospital
      editHospital(context,data){
          HospitalAPI.editHospital(data).then(function(response){
              context.commit('setEditHospitalStatus',response.data.code);
          })
      },
      //获取详情
      loadHospitalInfo(context,data){
          HospitalAPI.getHospitalInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setHospitalInfo',response.data.info);
              }
          })
      },
      //删除
      delHospital(context,data){
          HospitalAPI.delHospital(data).then(function(response){
                context.commit('setDelHospitalStatus',response.data.code);
          })
      }
   },
   getters:{
      getHospitalList:state =>{
         return state.hospitallist
      },
      getHospitalTotalCount: state =>{
         return state.hospital_total_count
      },
      getEditHospitalStatus:state=>{
          return state.editHospitalStatus;
      },
      getHospitalInfo:state => {
          return state.hospitalinfo;
      },
      getDelHospitalStatus:state => {
          return state.delHospitalStatus;
      },
      getAllHospitalLevel:state=>{
          return state.allhospitallevel;
      }
   }
}
